/*
* @overview: 
* @Author: wgf 
* @Date: 2024-04-22 13:24:55 
*/

import 'package:get/get.dart';
import 'package:flutter/material.dart';
import 'package:rc_widget/rc_widget.dart';

enum LoadingStatus {
  loading,
  error,
  success,
}

class AppGetxController extends GetxController {
  CancelToken cancelToken = CancelToken();

  /// 点击状态
  final RxBool _clickStatus = true.obs;

  /// 加载状态
  final Rx<LoadingStatus> _loadingStatus = Rx(LoadingStatus.loading);

  /// 可以点击
  bool get isClick => _clickStatus.value;

  /// 不可以点击
  bool get isNotClick => !_clickStatus.value;

  /// 组件加载状态
  LoadingStatus get loadingStatus => _loadingStatus.value;

  /// 组件加载成功
  bool get isLoadSuccess => loadingStatus == LoadingStatus.success;

  /// 组件加载未成功
  bool get isNotLoadSuccess => loadingStatus != LoadingStatus.success;

  /// 切换点击状态
  void toggleClickStatus(bool status) => _clickStatus.value = status;

  /// 切换加载类型状态
  void changeLoadingStatus(LoadingStatus status) => _loadingStatus.value = status;

  /// 关闭键盘
  void closeKeyboard() => FocusManager.instance.primaryFocus?.unfocus();

  @mustCallSuper
  @override
  void onClose() {
    cancelToken.cancel();
    super.onClose();
  }
}
